local wuxin = fk.CreateSkill {
  name = "lvshi__wuxin",
  tags = { Skill.Lord }
}

Fk:loadTranslationTable{
  ["lvshi__wuxin"] = "悟心",
  [":lvshi__wuxin"] = "主公技，你的手牌上限增加非群势力数；群势力角色的黑色判定牌生效前，你可亮出牌堆两张牌，打出其中一张牌代替之。",
  ["#lvshi__wuxin-ask"] = "你可用其中一张牌代替%dest的判定牌",

  ["$lvshi__wuxin1"] = "冀悟迷惑之心。",
  ["$lvshi__wuxin2"] = "吾已明此救世之术矣。",
}
local U = require "packages/utility/utility"

wuxin:addEffect(fk.AskForRetrial, {
  wuxin = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(wuxin.name) and target.kingdom == "qun" and data.card.color == Card.Black
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(2)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonJustMove,
      skillName = wuxin.name,
      proposer = player.id,
    })
    --local ids, _ = U.askforChooseCardsAndChoice(player, cards, {"OK"}, wuxin.name, "#lvshi__wuxin-ask::"..target.id)
    local card = room:askToChooseCard(player, {
      target = player,
      flag = { card_data = {{ wuxin.name, cards }} },
      skill_name = wuxin.name,
    })
    if card then
      room:changeJudge{
        card = Fk:getCardById(card),
        player = player,
        data = data,
        skillName = wuxin.name,
        response = true,
      }
    end
    room:cleanProcessingArea(cards)
  end,
})

wuxin:addEffect("maxcards", {
  correct_func = function(self, player)
    if player:hasSkill(wuxin.name) then
      local kingdoms = {}
      for _, p in ipairs(Fk:currentRoom().alive_players) do
        if p.kingdom ~= "qun" then
          table.insertIfNeed(kingdoms, p.kingdom)
        end
      end
      return #kingdoms
    end
  end,
})

return wuxin
